package com.lc1993929.mr.flow;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by LiuChang on 2017/11/6/006.
 */
public class FlowSumReducer extends Reducer<Text, FlowBean, Text, FlowBean> {
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        long upflowSum = 0;
        long dflowSum = 0;
        for (FlowBean flowBean : values) {
            upflowSum += flowBean.getUpFlow();
            dflowSum += flowBean.getDFlow();
        }
        context.write(key, new FlowBean(upflowSum, dflowSum));
    }
}
